

import UIKit

class BaseTableViewController: UITableViewController {
    
    /// 定义标记, 记录用户当前是否登录
    var login: Bool = true
    
    /// 访客视图
    var visitorView: VisitorView?
    
    override func loadView() {
        login ? super.loadView() : setupVisitorView()
    }
    /**
    初始化未登录界面
    */
    private func setupVisitorView()
    {
        // 1.创建访客视图
        visitorView = VisitorView()
        view = visitorView
        
        // 2.监听注册登录按钮
        visitorView?.loginButton .addTarget(self, action: Selector("loginDidClick"), forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.registerButton .addTarget(self, action: Selector("registerDidClick"), forControlEvents: UIControlEvents.TouchUpInside)
        
        // 3.添加导航条注册登录按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("registerDidClick"))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("loginDidClick"))
    }
    
    // MARK: - 内部控制方法
    @objc private func registerDidClick()
    {
        CHGLog("")
    }
    @objc private func loginDidClick()
    {
        CHGLog("")
    }
    
}
